<?php

//    ELGG profile view page

// Run includes
require_once(dirname(dirname(__FILE__)) . '/includes.php');
require_once($CFG->dirroot . 'profile/profile.class.php');
require_once(dirname(dirname(__FILE__)) . '/local/courses/lib.php');
require_once(dirname(dirname(__FILE__)) . '/local/skills/lib.php');

// define what profile to show
$profile_name = optional_param('profile_name', '', PARAM_ALPHANUM);
if (!empty($profile_name)) {
    $profile_id = user_info_username('ident', $profile_name);
}
if (empty($profile_id)) {
    $profile_id = optional_param('profile_id', -1, PARAM_INT);
}
// and the page_owner naturally
$page_owner = $profile_id;

define("context", "profile");
templates_page_setup();

// init library
$profile = new ElggProfile($profile_id); 
        
$title = user_name($profile_id); //$profile->display_name();
$body  = $profile->view();


if($USER->ident == $profile_id || isadmin()){
	$body .= '<div class="infoholder">';
	$body .= displayUserCourses(false,false,"<div class=\"fieldname\"><h3>Courses and Awards</h3></div>");
	$body .= '</div>';
	
	$body .= '<div class="infoholder">';
	$body .= displayUserSkills(false,false,"<div class=\"fieldname\"><h3>Skills</h3></div>");
	$body .= '</div>';
}
$body  = templates_draw( array(
                               'context' => 'contentholder',
                               'title' => $title,
                               'body' => $body
                               ));

echo templates_page_draw(array($title, $body));

?>